
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta charset="utf-8" />
    <title>ambient.fill_nc_db &#8212; Texas A&amp;M Oil spill / Outfall Calculator 2.1.0 documentation</title>
    <link rel="stylesheet" href="../../_static/alabaster.css" type="text/css" />
    <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
    <script src="../../_static/jquery.js"></script>
    <script src="../../_static/underscore.js"></script>
    <script src="../../_static/doctools.js"></script>
    <script src="../../_static/language_data.js"></script>
    <link rel="index" title="Index" href="../../genindex.html" />
    <link rel="search" title="Search" href="../../search.html" />
    <link rel="next" title="ambient.extract_profile" href="ambient.extract_profile.html" />
    <link rel="prev" title="ambient.create_nc_db" href="ambient.create_nc_db.html" />
   
  <link rel="stylesheet" href="../../_static/custom.css" type="text/css" />
  
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  </head><body>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  <div class="section" id="ambient-fill-nc-db">
<h1>ambient.fill_nc_db<a class="headerlink" href="#ambient-fill-nc-db" title="Permalink to this headline">¶</a></h1>
<dl class="function">
<dt id="ambient.fill_nc_db">
<code class="sig-prename descclassname">ambient.</code><code class="sig-name descname">fill_nc_db</code><span class="sig-paren">(</span><em class="sig-param">nc</em>, <em class="sig-param">data</em>, <em class="sig-param">var_symbols</em>, <em class="sig-param">var_units</em>, <em class="sig-param">comments</em>, <em class="sig-param">z_col=0</em><span class="sig-paren">)</span><a class="reference internal" href="../../_modules/ambient.html#fill_nc_db"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#ambient.fill_nc_db" title="Permalink to this definition">¶</a></dt>
<dd><p>Add data to a netCDF4-classic ambient profile dataset</p>
<p>This function adds data to a netCDF4-classic dataset for a single CTD
profile.  It is expected that this function could be called multiple 
times to completely fill in a profile database.  As data are added, this 
method interpolates the new data to match the current z-coordinates if 
they are already present in the dataset.</p>
<dl class="field-list">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><dl class="simple">
<dt><strong>nc</strong><span class="classifier">netCDF4 dataset object</span></dt><dd><p>This is the existing netCDF dataset object that will receive the data
stored in <cite>data</cite>.</p>
</dd>
<dt><strong>data</strong><span class="classifier">ndarray</span></dt><dd><p>Table of data to add to the netCDF database.  If it contains more
than one variable, the data are assumed to be arranged in columns.</p>
</dd>
<dt><strong>var_symbols</strong><span class="classifier">string list</span></dt><dd><p>List of string symbol names (e.g., T, S, P, etc.) in the same order 
as the columns in the data array.  For chemical properties, use the 
key name in the <cite>chemical_properties</cite> database.</p>
</dd>
<dt><strong>var_units</strong><span class="classifier">string list</span></dt><dd><p>List of units associated with each variable in the <cite>var_symbols</cite> list.</p>
</dd>
<dt><strong>comments</strong><span class="classifier">string list</span></dt><dd><p>List of comments associated with each variable in the <cite>var_symbols</cite>
list.  As a minimum, this list should include the indications 
‘measured’ or ‘derived’ or some similar indication of the source of
the data.</p>
</dd>
<dt><strong>z_col</strong><span class="classifier">integer, default is 0</span></dt><dd><p>Column number of the column containing the depth data.  The first 
column is numbered zero.</p>
</dd>
</dl>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><dl>
<dt><strong>nc</strong><span class="classifier"><cite>netCDF4.Dataset</cite> object</span></dt><dd><p>Returns the updated netCDF4 dataset with the data and metadata 
included.</p>
</dd>
</dl>
</dd>
<dt class="field-odd">Raises</dt>
<dd class="field-odd"><dl class="simple">
<dt>ValueError :</dt><dd><p>The input data array must always include a column of depths.  If the
input array contains a single column and the netCDF database already
has a depth array, a <cite>ValueError</cite> is raised since it would appear the 
user is trying to replace the existing depth data in the netCDF 
database.  If such an action is required, build a new netCDF database 
from scratch with the correct depth data.</p>
</dd>
<dt>ValueError :</dt><dd><p>This function checks whether the units supplied by the user in the 
list <cite>var_units</cite> match those expected by the database.  If not, a 
<cite>ValueError</cite> is raised with a message indicating which units are 
incompatible.</p>
</dd>
</dl>
</dd>
</dl>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference internal" href="ambient.create_nc_db.html#ambient.create_nc_db" title="ambient.create_nc_db"><code class="xref py py-obj docutils literal notranslate"><span class="pre">create_nc_db</span></code></a></dt><dd></dd>
</dl>
</div>
<p class="rubric">Notes</p>
<p>Symbol names in the <code class="docutils literal notranslate"><span class="pre">TAMOC</span></code> modeling suite are <cite>z</cite> (depth, positive down
from the sea surface), <cite>temperature</cite>, <cite>salinity</cite>, <cite>pressure</cite>, and chemical
names from the <cite>chemical_properties</cite> database (see 
<code class="docutils literal notranslate"><span class="pre">./data/ChemData.csv</span></code>).  Other names will be treated exactly like the 
chemical names, but will likely either be unused by the <code class="docutils literal notranslate"><span class="pre">TAMOC</span></code> modeling
suite or generate errors when a different symbol is expected.  Hence, it 
is the responsibility of the user to ensure that all symbol names are 
correct when this function is called.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">ds</span> <span class="o">=</span> <span class="n">Dataset</span><span class="p">(</span><span class="s1">&#39;./test/output/test_ds.nc&#39;</span><span class="p">,</span> <span class="s1">&#39;a&#39;</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">z</span> <span class="o">=</span> <span class="n">ds</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;z&#39;</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">zp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="n">z</span><span class="o">.</span><span class="n">valid_min</span><span class="p">,</span> <span class="n">z</span><span class="o">.</span><span class="n">valid_max</span><span class="p">])</span>  <span class="c1"># Depth range</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">yp</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="mf">9.15</span><span class="p">,</span> <span class="mf">5.20</span><span class="p">])</span> <span class="o">/</span> <span class="mi">1000</span>         <span class="c1"># Synthetic data</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">data</span> <span class="o">=</span> <span class="n">np</span><span class="o">.</span><span class="n">vstack</span><span class="p">((</span><span class="n">zp</span><span class="p">,</span> <span class="n">yp</span><span class="p">))</span><span class="o">.</span><span class="n">transpose</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ds</span> <span class="o">=</span> <span class="n">fill_nc_db</span><span class="p">(</span><span class="n">ds</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;z&#39;</span><span class="p">,</span> <span class="s1">&#39;oxygen&#39;</span><span class="p">],</span> <span class="p">[</span><span class="s1">&#39;m&#39;</span><span class="p">,</span> <span class="s1">&#39;kg/m^3&#39;</span><span class="p">],</span> 
<span class="go">                    [&#39;synthetic&#39;, &#39;synthetic&#39;], z_col=0)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="nb">print</span> <span class="n">ds</span><span class="o">.</span><span class="n">variables</span><span class="o">.</span><span class="n">keys</span><span class="p">()</span>
<span class="go">[&#39;time&#39;, &#39;lat&#39;, &#39;lon&#39;, &#39;z&#39;, &#39;temperature&#39;, &#39;salinity&#39;, &#39;pressure&#39;, &#39;S&#39;, </span>
<span class="go">&#39;T&#39;, &#39;oxygen&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">ds</span><span class="o">.</span><span class="n">variables</span><span class="p">[</span><span class="s1">&#39;oxygen&#39;</span><span class="p">][:]</span><span class="o">.</span><span class="n">shape</span>            <span class="c1"># Note interpolation</span>
<span class="go">(34,)</span>
</pre></div>
</div>
</dd></dl>

</div>


          </div>
          
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="../../index.html">Texas A&M Oil spill / Outfall Calculator</a></h1>








<h3>Navigation</h3>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="../../user_manual.html">TAMOC User Manual</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../unit_tests.html">Unit Tests</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary.html">Glossary</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../bugs.html">Reporting Bugs</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../readme.html">Read Me File</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../release.html">Release Notes</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../license.html">License</a></li>
</ul>

<div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="../../index.html">Documentation overview</a><ul>
  <li><a href="../../user_manual.html">TAMOC User Manual</a><ul>
  <li><a href="../../modules/ambient.html">Overview of Ambient Module</a><ul>
      <li>Previous: <a href="ambient.create_nc_db.html" title="previous chapter">ambient.create_nc_db</a></li>
      <li>Next: <a href="ambient.extract_profile.html" title="next chapter">ambient.extract_profile</a></li>
  </ul></li>
  </ul></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../../search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" />
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>








        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy;2020, Scott A. Socolofsky.
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 2.4.4</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.12</a>
      
      |
      <a href="../../_sources/autodoc/ambient/ambient.fill_nc_db.rst.txt"
          rel="nofollow">Page source</a>
    </div>

    

    
  </body>
</html>